package cn.fruitmarket.sellstrategy;

import cn.fruitmarket.utils.DateUtil;

import java.util.Date;

public class ReduceStrategy implements IStrategy {

    private double basePrice;
    private double reduceMoney;
    private Date startTime;
    private Date endTime;

    public ReduceStrategy(String startTimeStr,String endTimeStr,double basePrice,double reduceMoney) throws Exception{
        if(basePrice<0||reduceMoney<0) {
            throw new Exception("金额必须大于0");
        }
        if(reduceMoney>basePrice) {
            throw new Exception("减金额必须小于满金额");
        }
        this.startTime = DateUtil.parse(startTimeStr);
        this.endTime = DateUtil.parse(endTimeStr);
        this.basePrice = basePrice;
        this.reduceMoney = reduceMoney;
    }
    public double realPrice(Date carDate,double consumePrice) {
        if (consumePrice >= basePrice) {
            ////如果是每满100减10，可以迭代减，直到不够减. 或者用整除求出要减几次也可以。
            return consumePrice - reduceMoney;
        } else {
            return consumePrice;
        }
    }
}
